import { BasicColumn, FormSchema } from '@/components/Table';
import { dateUtil } from '@/utils/dateUtil';

export const rechargeFormSchema: FormSchema[] = [
  {
    field: 'companyId',
    label: '公司主键',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'companyName',
    label: '公司名称',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'companyUserName',
    label: '账号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'companyBalance',
    label: '当前余额',
    component: 'InputNumber',
    componentProps: {
      precision: 2,
      min: 0,
      max: 100000000,
    },
    required: false,
  },
  {
    field: 'amount',
    label: '充值金额',
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'payMethodId',
    label: '充值方式',
    component: 'Select',
    componentProps: {
      options: [{ name: '银行转账', id: '7' }],
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    required: true,
  },
  {
    field: 'memo',
    label: '备注',
    component: 'InputTextArea',
  },
  {
    field: 'sysAdminName',
    label: '操作人',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
];
export const refundFormSchema: FormSchema[] = [
  {
    field: 'companyId',
    label: '公司主键',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'companyName',
    label: '公司名称',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'companyUserName',
    label: '账号',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
  {
    field: 'companyBalance',
    label: '当前余额',
    component: 'InputNumber',
    componentProps: {
      precision: 2,
      min: 0,
      max: 100000000,
    },
    required: false,
  },
  {
    field: 'amount',
    label: '退款金额',
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'payMethodId',
    label: '退款方式',
    component: 'Select',
    componentProps: {
      options: [{ name: '银行转账', id: '7' }],
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    required: true,
  },
  {
    field: 'memo',
    label: '备注',
    component: 'InputTextArea',
  },
  {
    field: 'sysAdminName',
    label: '操作人',
    component: 'Input',
    required: false,
    dynamicDisabled: true,
  },
];
export const companyFormSchema: FormSchema[] = [
  {
    field: 'id',
    label: '企业id',
    component: 'Input',
    show: false,
    required: false,
  },
  {
    field: 'name',
    label: '企业名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'bankName',
    label: '开户行',
    component: 'Input',
    required: false,
  },
  {
    field: 'bankAccount',
    label: '开户账号',
    component: 'Input',
    required: false,
  },
  {
    field: 'bankAddress',
    label: '开户地址',
    component: 'Input',
    required: false,
  },
  {
    field: 'username',
    label: '用户名',
    component: 'Input',
    required: false,
    dynamicDisabled: ({ values }) => {
      return values.id;
    },
  },
  {
    field: 'password',
    label: '密码',
    component: 'Input',
    required: false,
    ifShow: ({ values }) => {
      return !values.id;
    },
  },
  {
    field: 'adminName',
    label: '负责人姓名',
    component: 'Input',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        disabled: formModel.id,
      };
    },
  },
  {
    field: 'adminMobile',
    label: '负责人手机',
    component: 'Input',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        dynamicDisabled: formModel.id,
      };
    },
  },
  {
    field: 'perCarMaxAmount',
    label: '单次冻结金额',
    component: 'InputNumber',
    componentProps: {
      min: 0,
      max: 100000000,
    },
    required: true,
  },
  {
    field: 'canVin',
    label: '是否可以VIN启动',
    component: 'RadioGroup',
    componentProps: {
      options: [
        {
          label: '是',
          value: '1',
        },
        {
          label: '否',
          value: '0',
        },
      ],
    },
    required: false,
  },
  {
    field: 'standardId',
    label: '计费标准',
    component: 'ApiSelect',
    componentProps: {
      api: '/chargeStandard/ChargeStandard/listData',
      treeDefaultExpandAll: false,
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    required: true,
  },
];
export const carTeamFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '车队名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'companyId',
    label: '车队名称',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    required: false,
    show: false,
  },
];
export const carFormSchema: FormSchema[] = [
  {
    field: 'licenseNo',
    label: '车牌号',
    component: 'Input',
    required: true,
  },
  {
    field: 'companyId',
    label: '企业id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'memberId',
    label: '人员id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'carTeamId',
    label: '车队名称',
    component: 'ApiSelect',
    componentProps: ({ formModel }) => {
      return {
        showSearch: true,
        api: '/admin/car_team/list',
        valueField: 'id',
        labelField: 'name',
        // options: [
        //   { id: 999, value: 'test' },
        //   { id: 888, name: 'test2' },
        //   { id: 8884, name: 'test3' },
        //   { id: 999, name: 'test' },
        //   { id: 888, name: 'test2' },
        //   { id: 8884, name: 'test3' },
        // ],

        params: { companyId: formModel.companyId },
        // immediate: true,
      };
    },
    required: true,
  },
  {
    field: 'carVin',
    label: '车架号(VIN)',
    component: 'Input',
    required: false,
  },
  {
    field: 'canVin',
    label: '是否可以VIN启动',
    component: 'Select',
    componentProps: {
      options: [
        { name: '是', id: '1' },
        { name: '否', id: '0' },
      ],
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
  },
  {
    field: 'name',
    label: '司机姓名',
    component: 'Input',
    required: false,
  },
  {
    field: 'mobile',
    label: '司机手机号',
    component: 'Input',
    required: false,
  },
  {
    field: 'carBrand',
    label: '品牌',
    component: 'Input',
    required: false,
  },
  {
    field: 'carSeries',
    label: '车系',
    component: 'Input',
    required: false,
  },
];
export const adminFormSchema: FormSchema[] = [
  {
    field: 'username',
    label: '用户名',
    component: 'Input',
    required: true,
  },
  {
    field: 'companyId',
    label: '企业id',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'id',
    label: '主键',
    component: 'Input',
    required: false,
    show: false,
  },
  {
    field: 'password',
    label: '初始密码',
    component: 'Input',
    required: true,
    ifShow: ({ values }) => {
      return !values.id;
    },
  },
  {
    field: 'password',
    label: '确认密码',
    component: 'Input',
    required: false,
  },
  {
    field: 'name',
    label: '姓名',
    component: 'Input',
    required: true,
  },
  {
    field: 'mobile',
    label: '手机',
    component: 'Input',
    required: true,
  },
  {
    field: 'permissions',
    label: '权限',
    component: 'CheckboxGroup',
    componentProps: {
      options: [
        { label: '充电管理', value: '1' },
        { label: '车辆管理', value: '2' },
        { label: '订单管理', value: '3' },
        { label: '发票管理', value: '4' },
        { label: '系统管理', value: '6' },
      ],
    },
  },
];
export const couPonColumns: BasicColumn[] = [
  {
    title: 'ID',
    dataIndex: 'id',
    width: 20,
  },
  {
    title: '优惠券名称',
    dataIndex: 'name',
    width: 80,
  },
  {
    title: '金额',
    dataIndex: 'amount',
    width: 50,
  },
  {
    title: '生效日期',
    dataIndex: 'startDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD');
    },
  },
  {
    title: '失效日期',
    dataIndex: 'endDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD');
    },
  },
];

export const columns: BasicColumn[] = [
  {
    title: '企业名称',
    dataIndex: 'name',
    width: 50,
  },
  {
    title: '账号',
    dataIndex: 'caUsername',
    width: 50,
    // customRender: ({ text }) => {
    //   if (text == '0') {
    //     return '正常';
    //   } else if (text == '1') {
    //     return '已冻结';
    //   }
    // },
  },
  {
    title: '负责人姓名',
    dataIndex: 'caName',
    width: 50,
  },
  {
    title: '负责人手机号',
    dataIndex: 'caMobile',
    width: 60,
  },
  {
    title: '充值总额',
    dataIndex: 'historyBalance',
    width: 70,
  },
  {
    title: '账户余额',
    dataIndex: 'balance',
    width: 70,
  },
  {
    title: '单车单次冻结金额',
    dataIndex: 'perCarMaxAmount',
    width: 30,
  },
  {
    title: '车辆总数',
    dataIndex: 'sumCarNum',
    width: 30,
  },
  {
    title: '累计充电次数',
    dataIndex: 'sumChargeTimes',
    width: 30,
  },
  {
    title: '累计充电订单',
    dataIndex: 'sumChargeTimes',
    width: 30,
  },
  {
    title: '累计电量',
    dataIndex: 'sumPower',
    width: 30,
  },
  {
    title: '累计总消费',
    width: 60,
    dataIndex: 'sumSpendMoney',
    // customRender: ({ record }) => {
    //   return record.historyBalance - record.balance;
    // },
  },
  {
    title: '电费',
    dataIndex: 'sumPowerMoney',
    width: 80,
  },
  {
    title: '服务费',
    dataIndex: 'sumServiceMoney',
    width: 80,
  },
  {
    title: '停车费',
    dataIndex: 'sumParkMoney',
    width: 80,
  },
  {
    title: '累计开票总额',
    dataIndex: 'sumInvoiceSpendMoney',
    width: 80,
  },
  {
    title: '开票金额(电费)',
    dataIndex: 'sumInvoicePowerMoney',
    width: 80,
  },
  {
    title: '开票金额(服务费)',
    dataIndex: 'sumInvoiceServiceMoney',
    width: 80,
  },
  {
    title: '开票金额(停车费)',
    dataIndex: 'sumInvoiceParkMoney',
    width: 80,
  },
  {
    title: '可开票金额',
    dataIndex: 'sumNotInvoiceSpendMoney',
    width: 80,
  },
  {
    title: '可开票金额(电费)',
    dataIndex: 'sumNotInvoicePowerMoney',
    width: 80,
  },
  {
    title: '可开票金额(服务费)',
    dataIndex: 'sumNotInvoiceServiceMoney',
    width: 80,
  },
  {
    title: '可开票金额(停车费)',
    dataIndex: 'sumNotInvoiceParkMoney',
    width: 80,
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
];
export const carTeamColumns: BasicColumn[] = [
  {
    title: '车队名称',
    dataIndex: 'name',
    width: 50,
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
];
export const carColumns: BasicColumn[] = [
  {
    title: '车牌号',
    dataIndex: 'licenseNo',
    width: 50,
  },
  {
    title: '车队',
    dataIndex: 'carTeamName',
    width: 50,
  },
  {
    title: '车架号',
    dataIndex: 'carVin',
    width: 50,
  },
  {
    title: '驾驶人',
    dataIndex: 'name',
    width: 50,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 50,
  },
  {
    title: '品牌',
    dataIndex: 'carBrand',
    width: 50,
  },
  {
    title: '车系',
    dataIndex: 'carSeries',
    width: 50,
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
];
export const adminColumns: BasicColumn[] = [
  {
    title: '用户名',
    dataIndex: 'username',
    width: 50,
  },
  {
    title: '姓名',
    dataIndex: 'name',
    width: 50,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 50,
  },
  {
    title: '主管理员',
    dataIndex: 'isSystem',
    width: 50,
    customRender: ({ text }) => {
      if (text == '0') {
        return '否';
      } else if (text == '1') {
        return '是';
      }
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
    width: 160,
    customRender: ({ text }) => {
      return dateUtil(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '开启状态',
    dataIndex: 'status',
    width: 50,
    customRender: ({ text }) => {
      if (text == '0') {
        return '已停用';
      } else if (text == '1') {
        return '已启用';
      }
    },
  },
];
export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '企业名称',
    component: 'Input',
    colProps: {
      span: 5,
    },
  },
  {
    field: 'startDate',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'endDate',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'canVin',
    label: 'VIN启用状态',
    component: 'Select',
    labelWidth: 90,
    componentProps: {
      options: [
        { name: '已禁用', id: '0' },
        { name: '已启用', id: '1' },
      ],
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    colProps: {
      span: 6,
    },
  },
];
export const adminSearchFormSchema: FormSchema[] = [
  {
    field: 'startDate',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'endDate',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'name',
    label: '管理员姓名',
    component: 'Input',
    colProps: {
      span: 5,
    },
  },
];
export const carTeamSearchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '车队名称',
    component: 'Input',
    colProps: {
      span: 5,
    },
  },
];
export const carSearchFormSchema: FormSchema[] = [
  {
    field: 'startDate',
    label: '开始时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'endDate',
    label: '结束时间',
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
    colProps: {
      span: 5,
    },
  },
  {
    field: 'licenseNo',
    label: '车牌号',
    component: 'Input',
    colProps: {
      span: 5,
    },
  },
  {
    field: 'canVin',
    label: 'VIN启用状态',
    component: 'Select',
    labelWidth: 90,
    componentProps: {
      options: [
        { name: '已禁用', id: '0' },
        { name: '已启用', id: '1' },
      ],
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    colProps: {
      span: 6,
    },
  },
  {
    field: 'carTeamId',
    label: '车队',
    component: 'ApiSelect',
    componentProps: {
      api: '/admin/car_team/list',
      treeDefaultExpandAll: false,
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
    },
    required: false,
  },
];
